<?php
define("DOMAIN","http://www.vipbanlv.com/");
define("DOMAIN_UPLOAD",DOMAIN.'upload/');
define("DOMAIN_JPUSH_APP_KEY",'06d05a23ec1eb3129823a6b3');
define("DOMAIN_JPUSH_MASTER_SECRET",'f77aa43cedacf5945db719b2');

$account_status = array(
    '1' => '提交中',
    '2' => '正常',
    '3' => '不可用'
);

$order_status = array(
    '0' => '下单',
    '1' => '支付成功',
    '2' => '已完成',
    '3' => '提现申请',
    '4' => '提现成功',
    '5' => '异常订单'
);

$msg_status = array(
    '0' => '未读',
    '1' => '已读'
);

$withdrawals_status = array(
    '0' => '申请中',
    '1' => '同意',
    '2' => '拒绝'
);

$order_type = array(
    1 => '购买账号',
    2 => 'v币充值'
);

$circle_type = array(
    1 => '最热',
    2 => '收藏',
    3 => '订单',
    4 => '我的',
    5 => '最新'
);

$indexlist_type = array(
    1 => 'toplist',
    2 => 'newsdata',
    3 => 'newsdataicon',
    4 => 'generalizelist',
    5 => 'vlivelist'
);

function dolog($content){
    $date = date('Ymd');
    $fp = fopen('./log/'.$date.'.log','a+');
    $wdata = date('Y-m-d H:i:s')."：".$content."\r\n";
    fwrite($fp, $wdata);
    fclose($fp);
}

function do_jpush($uid,$alert,$exreas){
    require_once './jpush/autoload.php';
    $client = new \JPush\Client(DOMAIN_JPUSH_APP_KEY, DOMAIN_JPUSH_MASTER_SECRET);
    try {
        $is_all = 0;
        if(!is_array($uid)){
            $uid = array($uid);
        }
        foreach ($uid as $k=>$v){
            if($v == 0){
                $is_all = 1;
            }
            $uid[$k] = (string)$v;
        }
        $re = $client->push()->setPlatform('all');
        
        if($is_all == 1){
            $re->addAllAudience();
        }else{
            $re->addAlias($uid);
        }
        
        $re->options(array('apns_production'=>true));
        
        $re->addIosNotification($alert,'default',1,false,'',$exreas)
        ->addAndroidNotification($alert,NULL,0,$exreas)
        ->send();
        dolog('ok-'.json_encode($re));
        return 1;
    } catch (\JPush\Exceptions\APIConnectionException $e) {
        dolog('err1-'.$e->__toString());
        return -1;
    } catch (\JPush\Exceptions\APIRequestException $e) {
        dolog('err2-'.$e->__toString());
        return -2;
    }
}